//
//  ViewController.m
//  Calendar
//
//  Created by M on 17/9/8.
//  Copyright © 2017年 1512. All rights reserved.
//

#import "ViewController.h"
#import "CollectionViewCell.h"
#import "DateTools.h"

@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
{
    UICollectionView *collec;
    
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //初始化UICollectionView
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    collec = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];
    [collec registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"collecCell"];
    collec.delegate = self;
    collec.dataSource = self;
    collec.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:collec];
    // Do any additional setup after loading the view, typically from a nib.
    NSDate *d = [NSDate date];
    NSLog(@"%ld",d.year);
}

//设置Cell的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((self.view.frame.size.width - 8)/7, 44);
}


//返回多少个Cell的集合
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

//设置返回的Cell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 35;
}

//Cell上下间距离
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 1;
}

//Cell左右间距离
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 1;
}

//设置Cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collecCell" forIndexPath:indexPath];
    
    cell.label.text = [NSString stringWithFormat:@"%ld",indexPath.row +1];
    //设置cell的颜色
     cell.backgroundColor = [UIColor redColor];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
